//
//  LHNavTitleChooseButton.m
//  LHImagePicker
//
//  Created by 刘辉 lewis on 2018/6/13.
//  Copyright © 2018年 刘辉 lewis. All rights reserved.
//

#import "LHNavTitleChooseButton.h"

#define kTitlePrecent 0.5
#define kImageViewWH  15

@implementation LHNavTitleChooseButton

-(instancetype)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        
        //        self.backgroundColor=[UIColor greenColor];
        self.titleLabel.textAlignment = NSTextAlignmentRight;
        //        self.titleLabel.backgroundColor=[UIColor blueColor];
        self.titleLabel.font = [UIFont boldSystemFontOfSize:16];
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        //self.imageView.layer.cornerRadius = kImageViewWH * 0.5;
        //        self.imageView.backgroundColor=[UIColor redColor];
        self.imageView.contentMode=UIViewContentModeScaleAspectFit;
        self.imageView.clipsToBounds=YES;
    }
    return self;
}

- (void)setFrame:(CGRect)frame {
    [super setFrame:CGRectMake(0, 0, 90, 44)];
    //    [super setFrame:CGRectMake(0, 0,self.superview.frame.size.width, self.superview.frame.size.height)];
}

#pragma mark 调整文字的位置和尺寸
- (CGRect)titleRectForContentRect:(CGRect)contentRect{
    CGFloat titleW = self.frame.size.width-kImageViewWH-5;
    CGFloat titleH = self.frame.size.height;
    CGFloat titleX = 0;
    CGFloat titleY = 0;
    return CGRectMake(titleX, titleY, titleW, titleH);
}

#pragma mark 调整图片的位置和尺寸
- (CGRect)imageRectForContentRect:(CGRect)contentRect{
    CGFloat imageW = kImageViewWH;
    CGFloat imageH = kImageViewWH;
    CGFloat imageX = self.frame.size.width-kImageViewWH;
    CGFloat imageY = (self.frame.size.height-kImageViewWH)*0.5;
    return CGRectMake(imageX, imageY, imageW, imageH);
}


@end
